package com.example.lihaoqian

import android.R
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // 设置标题
        title = "李浩仟2022110521"

        // ViewPager2 和 TabLayout
        val viewPager = findViewById<ViewPager2>(R.id.ViewPager)
        val tabLayout = findViewById<TabLayout>(R.id.tabLayout)
        val adapter: ViewPagerAdapter = ViewPagerAdapter(this)
        viewPager.adapter = adapter

        TabLayoutMediator(
            tabLayout, viewPager
        ) { tab, position -> tab.setText(if (position == 0) "单词列表" else "添加单词") }.attach()
    }
}